

/*返回数组序号*/
Num = function(e, eles) {
    for (var i = 0; i < eles.length; i++) {
        if (eles[i] == e) { return i; }
    }
}


/*DOM构造*/
var div2=function(id){return new HtmlEle.init(id);}
HtmlEle={
	init:function(id){
		this[0]=typeof(id)=="object"?id:document.getElementById(id);
		return this;
	},
	Css:function(s){
		for(var i in s){
			this[0].style[i]=s[i];
		}
	},
	Obj:function(){
		var obj=this[0];
		var objTop=obj.offsetTop,objLeft=obj.offsetLeft,objWidth=obj.offsetWidth,objHeight=obj.offsetHeight;
		return {top:objTop,right:objLeft+objWidth,bottom:objTop+objHeight,left:objLeft,width:objWidth,height:objHeight}
	},
	MoveReady:true,
	Move:function(s,point,endFc){
		var obj=this[0],n=0,v=s,main=this,v2=90;
		if(this.MoveReady==true){
			//main.MoveReady=false;

			var Top=function(){
				n=n<v2?n+1:n;
				var m=Sin(n,v);
				if(m<Math.abs(s)){obj.style.top=P-m+"px"}else{obj.style.top=P-s+"px";clearInterval(myMove);main.MoveReady=true;endFc?endFc():false;};
			}
			var Right=function(){
				n=n<v2?n+1:n;
				var m=Sin(n,v);
				if(m<Math.abs(s)){obj.style.left=P+m+"px"}else{obj.style.right=P+s+"px";clearInterval(myMove);main.MoveReady=true;endFc?endFc():false;};
			}
			var Bottom=function(){
				n=n<v2?n+1:n;
				var m=Sin(n,v);
				if(m<Math.abs(s)){obj.style.top=P+m+"px"}else{obj.style.top=P+s+"px";clearInterval(myMove);main.MoveReady=true;endFc?endFc():false;};
			}
			var Left=function(){
				n=n<v2?n+1:n;
				var m=Sin(n,v);
				if(m<Math.abs(s)){obj.style.left=P-m+"px"}else{obj.style.left=P-s+"px";clearInterval(myMove);main.MoveReady=true;endFc?endFc():false;};
			}

			switch(point){
				case "top" : var P=obj.offsetTop,Point=Top;break;
				case "right" : var P=obj.offsetLeft,Point=Right;break;
				case "bottom" : var P=obj.offsetTop,Point=Bottom;break;
				case "left" : var P=obj.offsetLeft,Point=Left;break;
			}

			var myMove=setInterval(Point,5)
		}
	},
	ScrollReady:true,
	Scroll:function(s,point,endFc){
		var obj=this[0],n=0,v=s,main=this,v2=90;
		if(this.ScrollReady==true){
			//main.ScrollReady=false;
			var Top=function(){
				n=n<v2?n+1:n;
				var m=Sin(n,v);
				if(m<Math.abs(s)){obj.scrollTop=P+m}else{obj.scrollTop=P+s;clearInterval(myMove);main.ScrollReady=true;endFc?endFc():false;};
			}
			var Right=function(){
				n=n<v2?n+1:n;
				var m=Sin(n,v);
				if(m<Math.abs(s)){obj.scrollLeft=P-m}else{obj.scrollLeft=P-s;clearInterval(myMove);main.ScrollReady=true;endFc?endFc():false;};
			}
			var Bottom=function(){
				n=n<v2?n+1:n;
				var m=Sin(n,v);
				if(m<Math.abs(s)){obj.scrollTop=P-m}else{obj.scrollTop=P-s;clearInterval(myMove);main.ScrollReady=true;endFc?endFc():false;};
			}
			var Left=function(){
				n=n<v2?n+1:n;
				var m=Sin(n,v);
				if(m<Math.abs(s)){obj.scrollLeft=P+m}else{obj.scrollLeft=P+s;clearInterval(myMove);main.ScrollReady=true;endFc?endFc():false;};
			}

			switch(point){
				case "top" : var P=obj.scrollTop,Point=Top;break;
				case "right" : var P=obj.scrollLeft,Point=Right;break;
				case "bottom" : var P=obj.scrollTop,Point=Bottom;break;
				case "left" : var P=obj.scrollLeft,Point=Left;break;
			}

			var myMove=setInterval(Point,5)
		}
	},
	Mouse:function(e,f){
		switch(e){
			case "click" : this[0].onclick=f;break;
			case "dbclick" : this[0].ondblclick=f;break;
			case "over" : this[0].onmouseover=f;break;
			case "out" : this[0].onmouseout=f;break;
			case "down" :this[0].onmousedown=f;break;
			case "up" : this[0].onmouseup=f;break;
		}
	},
	MouseSite:function(e){
		var e=e?e:window.event;
		return {x:e.clientX,y:e.clientY}
	},
	Create:function(ele,atrs){
		var obj=this[0],o=document.createElement(ele);
		if(atrs){
			for(var i in atrs){
				o.setAttribute(i,atrs[i]);
			}
		}
		return o;
	},
	MouseFollow:function(){
		var main=this;
		main[0].onmouseover=function(){this.style.cursor="pointer";}
		main[0].onmousedown=function(){
			var oX=main.MouseSite(arguments[0]).x-main.Obj().left,oY=main.MouseSite(arguments[0]).y-main.Obj().top;
			document.onmousemove=function(){
				main.Css({left:main.MouseSite(arguments[0]).x-oX+"px",top:main.MouseSite(arguments[0]).y-oY+"px"});
				return false;
			}
			return false;
		}
		main[0].onmouseout=function(){document.onmousemove="";}
		main[0].onmouseup=function(){document.onmousemove="";}
	},
	Alpha:function(str1,str2,endFc){
		var main=this;
		var str1=ie?str1:str1/100,str2=ie?str2:str2/100,v=ie?8:0.01,m=navigator.userAgent.indexOf('Opera')>= 0?5:1;
		v=str1>str2?v*-1:v;
		main.Css({opacity:str1,filter:"alpha(opacity="+String(str1)+")"});
		function alpha(){
			if(Math.round(str1*100)/100==str2){
				clearInterval(main.AlphaFc);
				main.Css({opacity:str2,filter:"alpha(opacity="+String(str2)+")"});
				endFc?endFc():false;
			}else{
				main.Css({opacity:str1+v,filter:"alpha(opacity="+String(str1+v)+")"});
				str1+=v;
			}
		}
		main.AlphaFc=setInterval(alpha,m);
	},
	ObjSize:function(o,atr,endFc){
		var oW=o.offsetWidth,oH=o.offsetHeight,Nl=true;
		var oSize=function(str,value){
			var str1=str=="width"?oW:oH,s=0,m=navigator.userAgent.indexOf('Opera')>= 0?5:1;
			var n=0,v=Math.abs(str1-value),f=str1<value?1:-1,v2=90;
			function init(){
				n=n<v2?n+1:n;
				var m=Sin(n,v)*f;
				if(Math.abs(m)<v){o.style[str]=str1+m+"px";}else{clearInterval(myInit);o.style[str]=value+"px";if(endFc){if(Nl){endFc();Nl=false}}}
			}
			var myInit=setInterval(init,m);
		}
		for(var i in atr){
			new oSize(i,atr[i]);
		}
	},
	Ban:function(h,WrapId){
		var main=this;
		var myScroll=function(){
			var h1=main[0].offsetTop,h2=WrapId?div(WrapId).scrollTop:document.documentElement.scrollTop,h0=h2+h,s=Math.abs(h1-h0);
			if(h1>h0){
				div2(main[0]).Move(s,"top");
			}else if(h1<h0){
				div2(main[0]).Move(s,"bottom");
			}
		}
		main.myBanMove=setInterval(myScroll,1000);
	}
}
HtmlEle.init.prototype=HtmlEle;

var tabFocus=function(Wrap,Tag,Tag2,links,e){
	this.wrap=div2(Wrap);
	var navWrap=Wrap+"Nav";
	this.navs2=div2(navWrap)[0].getElementsByTagName(Tag);
	this.navs=new Array();
	for(var i=0;i<this.navs2.length;i++){
		if(this.navs2[i].className!="more")
			this.navs.push(this.navs2[i]);
	}
	this.eles=this.wrap[0].getElementsByTagName(Tag2);
	this.navClass=[];
	this.wrap2=document.getElementById(Wrap+"2")?document.getElementById(Wrap+"2"):false;
	this.eles2=this.wrap2?this.wrap2.getElementsByTagName("ul"):false;
	links?this.anchor=div2(Wrap+"More")[0]:false;
	for(var i=0;i<this.navs.length;i++){
		this.navClass.push(this.navs[i].className);
	}
	this.eleClass=this.eles[0].className;
	this.navs[0].className=this.navClass[0]+" "+this.navClass[0]+"Cur";
	this.eles[0].className=this.eleClass+" on";
	this.eles2?this.eles2[0].className=this.eleClass+" on":false;
	links?this.anchor.href=links[0]:false;
	var main=this;
	var e=e?e:"over";
	for(var i=0;i<main.navs.length;i++){
		div2(main.navs[i]).Mouse(e,function(){
			var n=Num(this,main.navs);
			main.reSet();
			links?main.anchor.href=links[n]:false;
			this.className=main.navClass[n]+" "+main.navClass[n]+"Cur";
			main.eles[n].className=main.eleClass+" on";
			main.eles2?main.eles2[n].className=main.eleClass+" on":false;
		})
	}
}
tabFocus.prototype.reSet=function(){
	var main=this;
	for(var i=0;i<main.navs.length;i++){
		main.navs[i].className=main.navClass[i];
		main.eles[i].className=main.eleClass;
		main.eles2?main.eles2[i].className=main.eleClass:false;
	}
}